import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class Solution {
    List<List<Integer>> ret = new ArrayList<>();

    List<Integer> path = new ArrayList<>();

    int len;

    public List<List<Integer>> subsets(int[] nums) {
        len = nums.length;

        dfs(nums, 0);

        return ret;
    }

    public void dfs(int[] nums, int pos) {

        if (pos == len) {
            ret.add(new ArrayList<>(path));
            return;
        }



        //选
        path.add(nums[pos]);
        dfs(nums, pos + 1);

        //回溯
        path.remove(path.size() - 1);

        //不选
        dfs(nums, pos + 1);
    }

    public void dfs2(int[] nums, int pos) {

        ret.add(new ArrayList<>(path));

        for (int i = pos; i < len; i++) {
            path.add(nums[i]);
            // Collections.sort(path);
            // if (!ret.contains(path)) {
            //     ret.add(new ArrayList<>(path));
            // }
            // ret.add(new ArrayList<>(path));
            dfs(nums, i + 1);

            //回溯
            path.remove(path.size() - 1);
        }

    }
}
